package com.tan.connection.datatype;

import redis.clients.jedis.Jedis;

import java.util.logging.Logger;

public class RedisSet {
    private static Logger logger = Logger.getLogger(RedisSet.class.getName());
    public static void main(String[] args) {
        Jedis jedis = new Jedis("172.21.50.136",6379);
        jedis.flushDB();
        logger.info("=================向集合中添加元素(重复)=======================");
        logger.info("set添加元素"+jedis.sadd("eleSet","e6","e1","e3","e4","e2","e5","e7"));
        logger.info(""+jedis.sadd("eleSet","e10"));
        logger.info(""+jedis.sadd("eleSet","e10"));
        logger.info("eleSet的所有元素为："+jedis.smembers("eleSet"));
        logger.info("删除一个元素e0："+jedis.srem("eleSet","e1"));
        logger.info("eleSet的所有元素为："+jedis.smembers("eleSet"));
        logger.info("删除二个元素e7 和 e6："+jedis.srem("eleSet","e7","e6"));
        logger.info("eleSet的所有元素为："+jedis.smembers("eleSet"));
        logger.info("随机的移除集合中的一个元素："+jedis.spop("eleSet"));
        logger.info("随机的移除集合中的一个元素："+jedis.spop("eleSet"));
        logger.info("eleSet的所有元素为："+jedis.smembers("eleSet"));
        logger.info("eleSet的所有元素的个数："+jedis.scard("eleSet"));
        logger.info("e3是否在eleSet中："+jedis.sismember("eleSet","e3"));
        logger.info("e1是否在eleSet中："+jedis.sismember("eleSet","e1"));
        logger.info("e20是否在eleSet中："+jedis.sismember("eleSet","e20"));
        logger.info("==============================");
        logger.info("eleSet1："+jedis.sadd("eleSet1","e1","e2","e3","e6","e8","e33","e4"));
        logger.info("eleSet1："+jedis.sadd("eleSet2","e1","e2","e3","e6"));
        logger.info("将eleSet1中删除e1并存入eleSet3中："+jedis.smove("eleSet1","eleSet3","e3"));
        logger.info("将eleSet1中删除e2并存入eleSet3中"+jedis.smove("eleSet1","eleSet3","e6"));
        logger.info("eleSet1中的元素："+jedis.smembers("eleSet1"));
        logger.info("eleSet3中的元素："+jedis.smembers("eleSet3"));
        logger.info("==========================集合运算=========================");
        logger.info("eleSet1中的元素："+jedis.smembers("eleSet1"));
        logger.info("eleSet2中的元素："+jedis.smembers("eleSet2"));
        logger.info("eleSet1和eleSet2的交集："+jedis.sinter("eleSet1","eleSet2"));
        logger.info("eleSet1和eleSet2的并集："+jedis.sunion("eleSet1","eleSet2"));
        logger.info("eleSet1和eleSet2的差集："+jedis.sdiff("eleSet1","eleSet2"));
        jedis.sinterstore("eleSet4","eleSet1","eleSet2");
        logger.info("eleSet4中的元素"+jedis.smembers("eleSet4"));
    }
}
